Skip to content

feat: add optional dependency groups for graph and NLP extras#904

Merged
jhnwu3 merged 2 commits intosunlabuiuc:masterfrom
haoyu-haoyu:feat/optional-dependency-groups
Mar 27, 2026
Merged

feat: add optional dependency groups for graph and NLP extras#904
jhnwu3 merged 2 commits intosunlabuiuc:masterfrom
haoyu-haoyu:feat/optional-dependency-groups

Conversation

@haoyu-haoyu
Copy link
Copy Markdown
Contributor

Summary

Add [project.optional-dependencies] to pyproject.toml so users can install domain-specific dependencies via standard pip extras.

Closes #890

Usage

pip install pyhealth[graph]   # for GraphCare, knowledge graphs
pip install pyhealth[nlp]     # for NLP metrics (BLEU, ROUGE, edit distance)

Groups added

graph

  • torch-geometric>=2.6.0

Used by: graphcare.py, bat_gnn.py, knowledge_graph.py, graph_processor.py, datasets/utils.py

The codebase already has try/except ImportError guards with HAS_PYG flags — this just makes the dependency installable through standard packaging.

nlp

  • editdistance~=0.8.1
  • rouge_score~=0.1.2
  • nltk~=3.9.1

Used by: pyhealth/nlp/metrics.py (EditDistance, BLEU, ROUGE scorers)

Version pins match the requirements already declared in each scorer class's packages() method.

No breaking changes

Existing pip install pyhealth behavior is unchanged — these are optional extras that users opt into explicitly.

…uiuc#890)

Add [project.optional-dependencies] to pyproject.toml so users can
install domain-specific dependencies via pip extras:

  pip install pyhealth[graph]   # torch-geometric for GraphCare, KG
  pip install pyhealth[nlp]     # editdistance, rouge_score, nltk

The codebase already uses try/except ImportError with HAS_PYG flags
for torch-geometric, and the NLP metrics define their required
versions in each scorer class. This change exposes those dependencies
through standard Python packaging so pip can resolve them.

Version pins match the requirements declared in the code:
- editdistance~=0.8.1 (pyhealth/nlp/metrics.py:356)
- rouge_score~=0.1.2 (pyhealth/nlp/metrics.py:415)
- nltk~=3.9.1 (pyhealth/nlp/metrics.py:397)
- torch-geometric>=2.6.0 (compatible with PyTorch 2.7)

Closes sunlabuiuc#890
@jhnwu3 jhnwu3 requested a review from plandes March 22, 2026 22:19
@jhnwu3
Copy link
Copy Markdown
Collaborator

jhnwu3 commented Mar 22, 2026

Poking @plandes here as it's relevant to the dependency plan we had for the NLP module we want to build.

Copy link
Copy Markdown
Collaborator

@jhnwu3 jhnwu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

Copy link
Copy Markdown
Collaborator

@jhnwu3 jhnwu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oop, nvm. Sorry at eye doctor. We have a CI break here.

Copy link
Copy Markdown
Collaborator

@plandes plandes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails because the optional dependencies needs to start on line 62. However you added it in an already existing table (project) on line 49.

…ture

Move [project.optional-dependencies] from between dependencies and
license (line 49) to after keywords (line 62), before [project.urls].

In TOML, a sub-table header like [project.optional-dependencies]
closes the parent [project] table, so placing it before license and
keywords caused those fields to be excluded from [project]. This
broke CI validation.

Verified with tomllib that all project fields (name, license,
keywords, optional-dependencies, urls) parse correctly under
[project].
Copy link
Copy Markdown
Collaborator

@jhnwu3 jhnwu3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @plandes !!!

@jhnwu3 jhnwu3 merged commit c02f873 into sunlabuiuc:master Mar 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need to create pyhealth[nlp] pyhealth[graph] dependencies in the .toml file

3 participants